package com.net.xpay.stat.task;


import com.net.common.util.SerializationUtil;
import com.net.xpay.common.domain.DailyTaskRecord;
import com.net.xpay.common.enums.systemTask.DailyTaskName;
import com.net.xpay.common.helper.NoticeHelper;
import com.net.xpay.common.service.DailyTaskService;
import com.net.xpay.common.service.PartnerSafePaySettleService;
import com.net.xpay.common.service.impl.AbstractDailyTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 anno
 * 合伙人每日结算
 */
@Service
@Slf4j
public class PartnerSafePaySettleDailyTask extends AbstractDailyTaskService implements DailyTaskService {

    @Autowired
    private PartnerSafePaySettleService partnerSafePaySettleService;

    @Autowired
    private NoticeHelper noticeHelper;

    @Override
    protected boolean doWorkByDayInternal(DailyTaskRecord record) {
        log.warn("start safe pay partnerSettleDailyTask|day={}", record.getDay());
        partnerSafePaySettleService.statPartnerSettleRecord(record.getDay(), record);
        log.warn("end safe pay partnerSettleDailyTask|day={}", record.getDay());

        if (record.getFailedCount() != 0L) {
            log.warn("safe pay doWorkByDayInternal failedCount != 0| record={}", SerializationUtil.obj2String(record));
            noticeHelper.sendSystemMonitorNotice("safe pay doWorkByDayInternal failedCount != 0|recordId=" + record.getId(), "text");
            return false;
        }
        return true;
    }

    @Override
    protected String getDailyTaskName() {
        return DailyTaskName.PARTNER_SAFE_PAY_SETTLE_RECORD;
    }

    @Override
    protected int getFirstStartDayDiff() {
        return 7;
    }
}
